import 'dart:ui';
import 'package:flutterappyidongjingfen/LineChart/chart_bean.dart';
import 'package:flutterappyidongjingfen/LineChart/chart_line.dart';
import 'package:flutterappyidongjingfen/LineChart/base_painter.dart';
import 'package:flutterappyidongjingfen/LineChart/chart_line_painter.dart';
import 'package:flutter/material.dart';




class BrowseAllPage extends StatefulWidget{
  @override
  BrowseState createState() => BrowseState();
}

class BrowseState extends State<BrowseAllPage>{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      // 11 13 28
      backgroundColor: Color.fromRGBO(11, 13, 28, 1),
      body: Container(
          margin: const EdgeInsets.only(top: 0.0,left: 5,right: 5,bottom: 0),
          child:ListView(
            children: <Widget>[
              _buildChartLinwView(context, [
                Color.fromRGBO(86, 208, 234, 0.9),
                Color.fromRGBO(86, 208, 234, 0.1)
              ], [Color(0xFF006CED), Color(0xFF00C6FB)], "财务总览",Color.fromRGBO(66, 201, 250, 1),true),
              buildPostChartView(context),
              _buildChartLinwView(context, [
                Color.fromRGBO(248, 155, 140, 1),
                Color.fromRGBO(248, 155, 140, 0.1)
              ], [Color(0xFFF1586C), Color(0xFFFEA386)], "团金总览",Color.fromRGBO(249, 162, 150, 1),true),
            ],
          )
      )
    );
  }
}



Widget buildPostChartView(BuildContext context){
  return Container(
    child: Stack(
      children: <Widget>[
        _buildChartLinwView(context, [
          Color.fromRGBO(86, 208, 234, 0.9),
          Color.fromRGBO(86, 208, 234, 0.1)
        ], [Color(0xFF645AFF), Color(0xFFA573FF)], "同业总览",Color.fromRGBO(168, 129, 254, 1),false),
        Positioned(
          left: 40,
          right: 20,
          bottom: 50,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.end,
            children: <Widget>[
              drawPost(60),
              drawPost(20),
              drawPost(40),
              drawPost(80),
              drawPost(90),
              drawPost(60),
              drawPost(85),
              drawPost(72),
              drawPost(45),
              drawPost(70),
              drawPost(55),
              drawPost(56),
            ],
          ),
        ),
      ],
    ),
  );
}
 Widget drawPost(double value){
  return  SizedBox(
    width: 6,
    height: value,
    child: Container(
      decoration: ShapeDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [Colors.white,Colors.white30],
        ),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(3)),
      ),
    ),
  );
 }


Widget _buildChartLinwView(BuildContext context,List<Color> shaderColors,@required List<Color> LinearGradientColors,String title,Color yearButtonColor,bool isShowLine){
  var chartLine = ChartLine(
    chartBeans: [
      ChartBean(x: '', y: 80,color: Colors.green),
      ChartBean(x: '2月', y: 40,color: Colors.red),
      ChartBean(x: '', y: 150),
      ChartBean(x: '4月', y: 300),
      ChartBean(x: '', y: 80),
      ChartBean(x: '6月', y: 15),
      ChartBean(x: '', y: 10),
      ChartBean(x: '8月', y: 20),
      ChartBean(x: '', y: 60),
      ChartBean(x: '10月', y: 120),
      ChartBean(x: '', y: 300),
      ChartBean(x: '12月', y: 120),

    ],
    isShowHintX:true,
    hintXLineWidth: 0.5,
    hintXColor: Colors.white,
    size: Size(MediaQuery.of(context).size.width - 20,
        (MediaQuery.of(context).size.width - 40)*MediaQuery.of(context).size.width/MediaQuery.of(context).size.height),
    isCurve: true,
    lineWidth: 2.5,
    lineColor: isShowLine ? Colors.white : Colors.transparent,
    fontColor: Colors.white,
    xyColor: Colors.transparent,
    shaderColors: isShowLine ? shaderColors : null,
//    shaderColors: shaderColors,
    isShowBottomtHintX:false,
    fontSize: 10,
    numberOfhintX:4,
//    xTextPadding:16,
    yNum: 3,
//      duration:const Duration(milliseconds: 1200),
//      isAnimation: true,
    isReverse: false,
    isCanTouch: isShowLine ? true :false,
    isShowPressedHintLine: true,
    pressedPointRadius: 4,
    isShowXyRuler: false,
    pressedHintLineWidth: 0.5,
    pressedHintLineColor: Colors.white,
    duration: Duration(milliseconds: 1000),
//    backgroundColor: Colors.red,
  );
  String value = "1";
  return Card(

    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
//    margin: EdgeInsets.only(left: 5, right: 5, top: 8, bottom: 8),
    semanticContainer: true,
    child: Container(
        width:MediaQuery.of(context).size.width,
        height:(MediaQuery.of(context).size.width - 20)*480/710 ,
//      margin: EdgeInsets.only(left: 15, right: 15, top: 18, bottom: 18),
        decoration: new BoxDecoration(
          gradient:  LinearGradient(
            colors: LinearGradientColors,
          ),
        ),
        child:Stack(
          children: <Widget>[
            Positioned(
              top: 20,
              left: 20,
              child: Text(title,style: TextStyle(color: Colors.white,fontSize: 15.0),),
            ),
            Positioned(
              top: 15,
              right: 20,

              child: Container(
                width: 65,
                height: 25,
                decoration: ShapeDecoration(
                  color: yearButtonColor,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.5)),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    PopupMenuButton(
                      onSelected: (String selectValue) {
                      },
                      color: yearButtonColor,
                      itemBuilder: (BuildContext context) =>
                      <PopupMenuItem<String>>[
                        new PopupMenuItem(
                            value: "1",
//                            textStyle: TextStyle(fontSize: 20),
                            height: 30,
                            child:Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                new Text("2018", style: TextStyle(
                                    color: value == "1" ? Colors.white : Colors.grey),textAlign: TextAlign.center,)
                              ],
                            )
                        ),
                        new PopupMenuItem(
                            height: 30,
                            value: "2",
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                new Text("2017", style: TextStyle(
                                    color: value == "1" ? Colors.white : Colors.grey),textAlign: TextAlign.center,)
                              ],
                            )
                        ),
                        new PopupMenuItem(
                            height: 30,
                            value: "2",
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                new Text("2015", style: TextStyle(
                                    color: value == "1" ? Colors.white : Colors.grey),textAlign: TextAlign.center,)
                              ],
                            )
                        ),
                        new PopupMenuItem(
                            height: 30,

                            value: "2",
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                new Text("2014", style: TextStyle(
                                    color: value == "1" ? Colors.white : Colors.grey),textAlign: TextAlign.center,)
                              ],
                            )
                        ),
                        new PopupMenuItem(
                            height: 30,
                            value: "2",
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                new Text("2013", style: TextStyle(
                                    color: value == "1" ? Colors.white : Colors.grey),textAlign: TextAlign.center,)
                              ],
                            )
                        )
                      ],
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text("2019年", style: TextStyle(
                              color: Colors.white,
                              fontSize: 11)),
                          Icon(Icons.keyboard_arrow_down,color: Colors.white,size: 15)
                        ],
                      )
                    ),
                  ],
                ),
              )
            ),
            Positioned(
              top: 60,
              left: 20,
              child: Text("亿",style: TextStyle(color: Colors.white.withOpacity(0.6),fontSize: 11.0),),
            ),
            Positioned(
              top: 60,
              left: 5,
              right: 0,
              bottom: 15,
              child: chartLine,
            )
          ],
        )
    ),
    clipBehavior: Clip.antiAlias,
  );
}

